package cn.lanqiao.common.utils;

import java.util.Random;

/**
 * @author 舰长
 * 2022/3/15
 */
public class RandomUtil {

    /**
     * 根据长度生成随机数
     * @param length    长度
     * @return          结果
     */
    public static String getRandom(int length) {
        if(length < 0) return "0";
        StringBuilder minStr = new StringBuilder(length > 1 ? "1" : "0");
        StringBuilder maxStr = new StringBuilder("1");
        for (int i = 0; i < length-1; i++) {
            minStr.append("0");
            maxStr.append("0");
        }
        maxStr.append("0");
        int min = Integer.parseInt(minStr.toString());
        int max = Integer.parseInt(maxStr.toString());
        int res = min + ((int) (new Random().nextFloat() * (max - min)));
        return String.valueOf(res);
    }

    public static void main(String[] args) {

    }
}
